package com.yao.system.controller;


import com.yao.system.entity.Company;
import com.yao.system.entity.Job;
import com.yao.system.annotation.MyAnnotation;
import com.yao.system.entity.Result;
import com.yao.system.entity.dto.JobSerachDTO;
import com.yao.system.service.IJobService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("/job")
@RequiredArgsConstructor
public class JobController {

    private final IJobService jobService;

    /**
     * 新增岗位
     * @param job
     * @return
     */
    @MyAnnotation
    @PostMapping("/add")
    public Result addJob(@RequestBody Job job) {
        return jobService.addJob(job);
    }


    /**
     * 根据id 查询具体的岗位详情
     * @return
     */
    @MyAnnotation
    @GetMapping("/jobDetails/{id}")
    public Result getJobDetails(@PathVariable("id") Long id){
        return jobService.getJobDetails(id);
    }

    /**
     * 分页查询岗位列表
     * @param page
     * @param size
     * @return
     */
    //@MyLimit(value = 10,time = 1)
    @MyAnnotation
    @PostMapping("/list/{page}/{size}")
    public Result getList(@PathVariable(value = "page", required = false) Integer page,
                          @PathVariable(value = "size", required = false) Integer size,
                          @RequestBody JobSerachDTO dto) {
        return jobService.getList(page, size,dto);
    }

    /**
     * 获取我的岗位收藏列表
     * @return
     */
    @MyAnnotation
    @GetMapping("/collections/{page}/{size}")
    public Result getMyCollection(@PathVariable(value = "page", required = false) Integer page,
                                  @PathVariable(value = "size", required = false) Integer size){
        return jobService.getMyCollection(page,size);
    }


    /**
     * 获取用户已投递简历的岗位列表
     * @return
     */
    @MyAnnotation
    @GetMapping("/resume/{page}/{size}")
    public Result getResumeJobList(@PathVariable(value = "page", required = false) Integer page,
                                  @PathVariable(value = "size", required = false) Integer size){
        return jobService.getResumeJobList(page,size);
    }

    ///**
    // * 根据条件分页查询岗位列表
    // * @param page
    // * @param size
    // * @return
    // */
    //@MyAnnotation
    //@GetMapping("/search/{page}/{size}")
    //public Result getSearcherList(@PathVariable(value = "page", required = false) Integer page,
    //                              @PathVariable(value = "size", required = false) Integer size,
    //                              @RequestParam(value = "input",required = false)  String input) {
    //    return jobService.getSearcherList(page, size,input);
    //}


    /**
     * 查询企业用户发布的岗位
     * @param page
     * @param size
     * @param type
     * @return
     */
    @MyAnnotation
    @GetMapping("/user/{page}/{size}/{type}")
    public Result getUserJob(@PathVariable(value = "page", required = false) Integer page,
                             @PathVariable(value = "size", required = false) Integer size,
                             @PathVariable(value = "type", required = false) Integer type) {
        return jobService.getUserJob(page, size,type);
    }

    /**
     * 更新岗位信息
     * @param job
     * @return
     */
    @MyAnnotation
    @PutMapping("/update")
    public Result update(@RequestBody Job job) {
        return jobService.updateJob(job);
    }

    /**
     * 岗位上下架
     * @param id
     * @param type
     * @return
     */
    @MyAnnotation
    @PostMapping("/update/{id}/{type}")
    public Result updateType(@PathVariable("id") Long id, @PathVariable("type") Integer type) {
        return jobService.updateType(id, type);
    }

    /**
     * 删除岗位
     * @param id
     * @return
     */
    @MyAnnotation
    @PostMapping("/delete/{id}")
    public Result deleteJob(@PathVariable("id")Long id){
        return jobService.deleteJob(id);
    }

    @MyAnnotation
    @GetMapping("/count")
    public Result getJobAndResumeCount(){
        return jobService.getJobAndResumeCount();
    }



    /**
     * 管理员查询岗位列表
     */
    @MyAnnotation
    @GetMapping("/admin-list/{page}/{size}")
    public Result queryJobList(@PathVariable("page")Integer page,
                                   @PathVariable("size")Integer size){
        return jobService.queryJobList(page,size);
    }

    /**
     * 管理员修改岗位
     */
    @MyAnnotation
    @PostMapping("/admin-update")
    public Result updateJobAdmin(@RequestBody Job job){
        return jobService.updateJobAdmin(job);
    }

    /**
     * 管理员删除岗位
     */
    @MyAnnotation
    @PostMapping("/admin-delete")
    public Result deleteJobAdmin(@RequestBody Job job){
        jobService.removeById(job);
        return Result.ok("删除成功");
    }



}
